<?php
namespace Home\Model;
use Think\Model;
class GoodsModel extends Model 
{
    public function search($pageSize = 20)
	{
		/**************************************** 搜索 ****************************************/
		$where = array();
		if($goods_name = I('get.goods_name'))
			$where['goods_name'] = array('like', "%$goods_name%");
		if($goods_model = I('get.goods_model'))
			$where['goods_model'] = array('like', "%$goods_model%");
		if($batch = I('get.batch'))
			$where['batch'] = array('like', "%$batch%");
		/************************************* 翻页 ****************************************/
		$count = $this->where($where)->count();
		$page = new \Think\Page($count, $pageSize);
		// 配置翻页的样式
		$page->setConfig('prev', '上一页');
		$page->setConfig('next', '下一页');
		$data['page'] = $page->show();
		/************************************** 取数据 ******************************************/
		$data['data'] = $this->where($where)->limit($page->firstRow.','.$page->listRows)->select();
		return $data;
	}
}

